import { FilterSelectJSON } from "./static";

export const byKeysGetEnemptyResult = (source, keys) => {
    return keys.reduce((prev, current) => {
        const sourceValue = source[current];
        const { 
            label = "" 
        } = FilterSelectJSON.find(option => option.value === current);
        const shouldContinue = isUndefined(sourceValue) || !Boolean(sourceValue);
        const filtered = [{
            key: label,
            value: sourceValue
        }];

        if (shouldContinue) return prev;
        return prev.concat(filtered);
    }, []);
};

export const isUndefined = (v) => {
    return Reflect.toString.call(v) === "[object Undefined]";
};

export const isEmptyObject = (o) => {
    return Object.keys(o).length === 0;
};

export const refreshFormFilterKeys = (form) => {
    const tempFilterKeys = ["uid", "keywords", "phone"];
    for (let key in form) {
        if (tempFilterKeys.includes(key)) {
            form[key] = undefined;
        }
    };

    return form;
};